<?php
/*
 * @Author: cwj
 * @Date: 2019-12-20 09:54:03
 * @LastEditTime : 2020-01-03 14:25:12
 * @LastEditors  : Please set LastEditors
 * @Description: 命令下发 历史 
 * @FilePath: /ahsmp_3/application/adminapiv3/service/ClientCmdsHistory.php
 */
namespace app\adminapiv3\service;

use app\common\service;

class CmdsHistory extends Base
{
    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 09:55:15
     */
    function list ($limit)
    {
        $ServerSocketMessageHistory = new service\ServerSocketMessageHistory();
        $user = $this->getUserInfo();
        $return = $ServerSocketMessageHistory->list($user['id'], $limit);
        $return['data'] = $this->processList($return['data']);

        return $return;
    }

    /**
     * @name: 处理列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 11:19:24
     */
    function processList ($data)
    {
        if(empty($data))
        {
            return [];
        }
        
        foreach ($data as $v)
        {
            $host_id_a[] = $v['host_id'];
            $user_id_a[] = $v['user_id'];
        }

        $ServerUser = new service\ServerUser();
        $user_a = $ServerUser->getUserById($user_id_a);

        $Host = new service\Host();
        $host_a = $Host->hostList($host_id_a, 'id,name,ctime');

        foreach ($data as $k => $v)
        {
            $data[$k]['host'] = isset($host_a[$v['host_id']]) ? $host_a[$v['host_id']] : ['name'=>'该主机已被删除'];
            $data[$k]['user'] = isset($user_a[$v['user_id']]) ? $user_a[$v['user_id']] : ['show_name'=> '该用户已被删除'];
        }

        return $data;
    }

    /**
     * @name: 发送失败条数
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:07:45
     */
    function errorCount ()
    {
        $user = $this->getUserInfo();

        $ServerSocketMessageHistory = new service\ServerSocketMessageHistory();
        $return = $ServerSocketMessageHistory->toDo('errCount',[$user['id']]);

        return $return;
    }

    /**
     * @name: 忽略
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:24:33
     */
    function ignore ($id_s)
    {
        $ServerSocketMessageHistory = new service\ServerSocketMessageHistory();
        $ServerSocketMessageHistory->toDo('ignore', [$id_s]);
    }
}
